﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nim.IO
{
    class KeyBoard
    {
        //Returns a line of input from the keyboard
        public static string GetLine(string prompt)
        {
            Console.WriteLine(prompt);
            return Console.ReadLine();
        }

        //Returns a double, will re-ask if not a double
        public static double GetDouble(string prompt)
        {
            bool valid = false;
            double val = 0;

            do
            {
                try
                {
                    val = double.Parse(GetLine(prompt));
                    valid = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("NOT A DECIMAL! YOU SHOULD KNOW BETTER!");
                }
            } while (!valid);

            return val;
        }

        //Returns an int, will re-ask if not an int
        public static int GetInt(string prompt)
        {
            bool valid = false;
            int val = 0;

            do
            {
                try
                {
                    val = int.Parse(GetLine(prompt));
                    valid = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("NOT A NUMBER! YOU SHOULD KNOW BETTER!");
                }
            } while (!valid);

            return val;
        }
    }
}
